//
//  JSONCoder.swift
//  JLDiaryApp
//
//  Created by Jiang Chencheng on 2024/9/28.
//

import Foundation


enum JSONCoder {}

private extension JSONCoder {
    static let encoder = JSONEncoder()

    static let decoder = JSONDecoder()
}


extension JSONCoder {
    static func encode<Object: Encodable>(object: Object) throws -> Data {
        let data = try encoder.encode(object)
        return data
    }

    static func decode<Object: Decodable>(data: Data) throws -> Object {
        try decoder.decode(Object.self, from: data)
    }
}
